package com.iflytek.edu.controller;

import com.iflytek.edu.entity.User;
import com.iflytek.edu.common.base.BaseResponse;
import com.iflytek.edu.service.UserService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

/**
 *
 */
@IocBean // 声明为Ioc容器中的一个Bean
@At("/user") // 整个模块的路径前缀
@Ok("json:{locked:'password|salt',ignoreNull:true}") // 忽略password和salt属性,忽略空属性的json输出
@Fail("http:500") // 抛出异常的话,就走500页面
public class UserController extends BaseController {

    @Inject
    private UserService userService;


    @POST
    @At("/login")
    @Ok("json")
    public Object login() {
        BaseResponse response = new BaseResponse();
        return response.success("success");
    }


    @POST
    @At("/save")
    @Ok("json")
    public Object save(@Param("..")User user) {
        try{
            //userService.insert(user);
            //测试事务
            userService.testTrans(user);
        }catch (Exception e){
            e.printStackTrace();
            return BaseResponse.error(1,"error:"+e.getMessage());
        }
        return BaseResponse.success("success");
    }



}
